import LoggerUtil from '@/utils/LoggerUtil';
import Util from '@/utils/Util';
import GoodsInfo from '@/model/GoodsInfo';
import VipService from '@/service/VipService';
import OrderInfo from '@/model/OrderInfo';
import {OrderService} from '@/service/OrderService';
import { ConfigureResponse } from "@/protocol/response/CommonResponse";
import {CommonService} from "@/service/CommonService";
import UniUtil from "@/utils/UniUtil";
import Constant from "@/constant/Constants";
import { MyVue } from '@/common/MyVue';
import { Component, Setup } from "vue-facing-decorator";
@Component
export default class Recharge extends MyVue {
    showModal: boolean = false;
    goods = new Array<GoodsInfo>();
    goodsMap = new Map<number, GoodsInfo>();
    selectGoodsId: number = 0;
    configure = new ConfigureResponse();
    platform = 'android';
    async onShowModal() {
        this.platform = uni.getSystemInfoSync().platform.toLocaleLowerCase();
        let configure = await CommonService.getCongirue();
        Util.copy(this.configure, configure);
        let res = await VipService.getScoreGoods();
        this.goods.length = 0;
        this.goodsMap.clear();
        if (!Util.isEmpty(res)) {
            Util.copyList(this.goods, res, GoodsInfo);
            this.goods.forEach(element => {
                this.goodsMap.set(element.id, element);
            });
            this.selectGoodsId = this.goods[this.goods.length - 1].id;
        }
        this.showModal = true;
    }

    onGoodsSelect(e) {
        this.selectGoodsId = e.currentTarget.dataset.id;
    }

    onConfirm() {
        let selectGoods = this.goodsMap.get(this.selectGoodsId);
        let order = new OrderInfo();
        selectGoods.count = 1;
        order.goods.push(selectGoods);
        order.initDeliveryTime();
        let that = this;
        OrderService.createOrder(order, function () {
            that.onCloseModal();
            //that.refreshUserData();
        });
    }

    onCloseModal() {
        this.showModal = false;
    }

    showWxQrocde() {
        UniUtil.showWxQrocde(this.configure.wxQrcode);
    }
}